package com.tansun.easycare.rule.common.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import com.tansun.easycare.rule.common.DataCache;
import com.tansun.easycare.rule.common.DataParamTreeVO;
import com.tansun.easycare.rule.common.DataSetTreeVo;
import com.tansun.easycare.rule.common.model.BaseBean;
import com.tansun.easycare.rule.common.model.Bom;
import com.tansun.easycare.rule.common.model.BomField;
import com.tansun.easycare.rule.common.model.Domain;
import com.tansun.easycare.rule.common.model.DomainItem;
import com.tansun.easycare.rule.common.model.RuleParamField;
import com.tansun.easycare.rule.common.service.DataBomService;
import com.tansun.easycare.rule.common.web.model.ProjectInfo;
import com.tansun.easycare.rule.datamodel.dao.RuleDataDomainDao;
import com.tansun.easycare.rule.datamodel.dao.RuleDatamodelDao;
import com.tansun.easycare.rule.datamodel.dao.RuleDataparamsDao;
import com.tansun.easycare.rule.datamodel.dao.RuleDatasetDao;
import com.tansun.easycare.rule.datamodel.entity.RuleDataDomain;
import com.tansun.easycare.rule.datamodel.entity.RuleDataEntity;
import com.tansun.easycare.rule.datamodel.entity.RuleDatamodel;
import com.tansun.easycare.rule.datamodel.entity.RuleDataparams;
import com.tansun.easycare.rule.datamodel.entity.RuleDataset;
import com.tansun.easycare.rule.datamodel.entity.RuleEnum;
import com.tansun.easycare.rule.datamodel.service.RuleDataparamsService;
import com.tansun.easycare.rule.datamodel.service.RuleEnumService;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.rulemange.entity.RuleManage;
import com.tansun.easycare.rule.ruleproj.dao.RuleProjectDao;
import com.tansun.easycare.rule.ruleproj.dao.RuleProjectReferenceDao;
import com.tansun.easycare.rule.ruleproj.entity.RuleProject;
import com.tansun.easycare.rule.ruleproj.entity.RuleProjectRank;
import com.tansun.easycare.rule.ruleproj.service.RuleProjectRankService;
import com.tansun.rule.utils.MClass;
import com.tansun.rule.utils.MField;
import com.tansun.rule.utils.StringUtils;

import net.sf.cglib.beans.BeanCopier;

@Component
public class DataBomServiceImpl implements DataBomService {

	private static final Logger logger = LoggerFactory.getLogger(DataBomServiceImpl.class);
	
    @Autowired
    private RuleDatasetDao ruleDatasetDao;
    @Autowired
    private RuleDataparamsDao ruleDataparamsDao;
    @Autowired
    private RuleDataparamsService ruleDataparamsService;
    @Autowired
    private RuleDataDomainDao ruleDataDomainDao;
    @Autowired
    private RuleEnumService ruleEnumService;
    @Autowired
    private RuleProjectReferenceDao ruleReferenceDao;
    @Autowired
    private RuleProjectDao ruleProjectDao;
    @Autowired
    private RuleProjectRankService ruleProjectRankService;
    @Autowired
    private RuleDatamodelDao ruleDatamodelDao;
    
    

    /********数据模型信息缓存**********/
    public static Map<String,List<DataSetTreeVo>> PARAMAP = new HashMap<String, List<DataSetTreeVo>>();
    public static Map<String,Map<String, Bom>> BOMMAP = new HashMap<String, Map<String,Bom>>();

    @Override
    public Map<String, Domain> findDomainByProjectCode(String projectCode) {
    	
        Map<String, Domain> resultMap = new HashMap<String, Domain>();
    	String cacheKey = DataCache.getCacheKey(projectCode, DataCache.DOMAINCACHE_OPTION);
    	if(DataCache.canGetFromCache(cacheKey)) {
    		resultMap = (Map<String, Domain>) DataCache.getValue(cacheKey);
    	}else {
    		resultMap = new HashMap<String, Domain>();
	        RuleDataparams ruleDataparams = new RuleDataparams();
	        ruleDataparams.setProjectcode(projectCode);
//			List<RuleDataparams> list = this.ruleDataparamsDao.findListNoFuncparam(ruleDataparams);
//			List<RuleDataparams> listForBom = this.ruleDataparamsDao.findListForBom(ruleDataparams);
//			list.addAll(listForBom);
			List<RuleDataparams> list = this.ruleDataparamsDao.findListWithDomain(ruleDataparams);
            Map<String,List<RuleDataDomain>> mapRD = this.findDomainMap();

			Domain domain = null;
			List<RuleDataDomain> rdList = null;
	        List<DomainItem> itList = null;
	        DomainItem bf = null;
	        
	        for (RuleDataparams rdp : list) {
	            domain = new Domain();
	            domain.setId(rdp.getId());
	            domain.setName(rdp.getName());
	            domain.setLabel(rdp.getChzn());
	            domain.setDataType(rdp.getType());
	            domain.setDesc(rdp.getParamDesc());
	            domain.setType(BaseBean.TYPE_DOMAIN);
	            resultMap.put(rdp.getId(), domain);
	            itList = new ArrayList<DomainItem>();
	            domain.setDomainItems(itList);
	            rdList = mapRD.get(rdp.getId());
	            if( rdList != null && rdList.size() > 0 ) {
		            for (RuleDataDomain rdd : rdList) {
		                bf = new DomainItem();
		                bf.setId(rdd.getId());
		                bf.setName(rdd.getName());
		                bf.setLabel(rdd.getName());
		                bf.setType(BaseBean.TYPE_DOMAIN);
		                bf.setValue(rdd.getDomainValue());
		                itList.add(bf);
		            }
	            }
	        }
	        DataCache.setValue(cacheKey, resultMap);
    	}
        return resultMap;

    }

    @Override
	public List<RuleDataEntity> findRuleDataEntityListByRuleManage(RuleManage ruleManage){
    	List<RuleDataEntity> ruleDataEntitys = new ArrayList<RuleDataEntity>();
    	RuleDataset ruleDataset = new RuleDataset();
        ruleDataset.setProjectcode(ruleManage.getProjectCode());
        List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
        Map<String,List<RuleDataparams>> map2RDP = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(ruleManage.getProjectCode());
        for (RuleDataset rd : list) {
            List<RuleDataparams> rList = map2RDP.get(rd.getId());
            RuleDataEntity ruleDataEntity = new RuleDataEntity();
            ruleDataEntity.setRuleDataparams(rList);
            ruleDataEntity.setRuleDataset(rd);
            ruleDataEntitys.add(ruleDataEntity);
        }
        return ruleDataEntitys;
	}
    
    @SuppressWarnings("unchecked")
   	@Override
    public Map<String, Bom> findBomMapByProjectCode(String projectCode, String rankRelationId) {
       	Map<String, Bom> resultMap = null;
    	if(StringUtils.isNotEmpty(rankRelationId)) {
    		resultMap = createBomMapVo(projectCode,rankRelationId);
    	}
    	String parentRankId = null;
		RuleProjectRank parentNode = null;
    	try {
    		//层级Id为必传。
			parentNode = getCacheKeyWithRanRelation(projectCode, rankRelationId);
			parentRankId = parentNode.getId();
		}catch (Exception e){
			resultMap  = new HashMap<>();
//			return resultMap;
		}
		String cacheKey = DataCache.getCacheKey(projectCode+parentRankId, DataCache.BOMCACHE_OPTION);
//		if(DataCache.canGetFromCache(cacheKey)) {
//    		resultMap = (Map<String, Bom>) DataCache.getValue(cacheKey);
//    	}else {
			//查询所有的数据集变量
			List<String> rankIdStrList = getRankRelationInfo(projectCode,rankRelationId,"dataModel");
			Map<String,List<RuleDataparams>> mapAll = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
			resultMap = new HashMap<String, Bom>();
			//未查询到层级模型信息的话， 查找全部的变量信息
			if(rankIdStrList!=null&&rankIdStrList.size()>0){
				for(String rankId : rankIdStrList){
					RuleDatamodel ruleDatamodel = new RuleDatamodel();
					ruleDatamodel.setRankRelationId(rankId);
					ruleDatamodel.setProjectCode(projectCode);
					RuleDataset ruleDataset = new RuleDataset();
					List<RuleDatamodel> rankRuleDataModels = ruleDatamodelDao.findList(ruleDatamodel);
                    if(rankRuleDataModels!=null && rankRuleDataModels.size()>0){
                    	for(RuleDatamodel item : rankRuleDataModels){
							ruleDataset.setDatamodelid(item.getId());
							ruleDataset.setProjectcode(projectCode);
							List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
							createBomField(resultMap,mapAll,list);
						}
					}
				}
			}else {
				RuleDataset ruleDataset = new RuleDataset();
				ruleDataset.setProjectcode(projectCode);
				List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
				createBomField(resultMap,mapAll,list);
			}
			//查询所有的函数变量
			List<String> funcRankIdList = getRankRelationInfo(projectCode,rankRelationId,"funcparam");
			RuleDataset ruleDataset = new RuleDataset();
			ruleDataset.setProjectcode(projectCode);
			ruleDataset.setName("func");
			List<RuleDataset> funcDataSet = this.ruleDatasetDao.findList(ruleDataset);
			RuleDataparams rdps = new RuleDataparams();
			rdps.setProjectcode(projectCode);
			rdps.setFuncRankIdList(funcRankIdList);
			List<RuleDataparams> rFuncList =  this.ruleDataparamsDao.findListForBom(rdps);
			Map<String,List<RuleDataparams>> mapfunc = new HashMap<String,List<RuleDataparams>>();
			for(RuleDataparams rdp:rFuncList) {
				String key = rdp.getDatasetId();
				List<RuleDataparams> params = null;
				if(mapfunc.containsKey(key)) {
					params = mapfunc.get(key);
				}else {
					params = new ArrayList<RuleDataparams>();
					mapfunc.put(key, params);
				}
				params.add(rdp);
			}
			createBomField(resultMap,mapfunc,funcDataSet);
			//查询所有的内置变量
//			RuleDataset builtinDataset = new RuleDataset();
//			builtinDataset.setProjectcode(projectCode);
//			builtinDataset.setName("builtinParam");
//			List<RuleDataset> builtinDataSets = this.ruleDatasetDao.findList(builtinDataset);
//			if(builtinDataSets!=null && builtinDataSets.size()>0){
//				RuleDataparams builtinDataparam = new RuleDataparams();
//				builtinDataparam.setProjectcode(projectCode);
//				builtinDataparam.setDatasetId(builtinDataSets.get(0).getId());
//				List<RuleDataparams> builtinDataparams =  this.ruleDataparamsDao.findList(rdps);
//				Map<String,List<RuleDataparams>> builtinfunc = new HashMap<String,List<RuleDataparams>>();
//				for(RuleDataparams rdp:builtinDataparams) {
//					String key = rdp.getDatasetId();
//					List<RuleDataparams> params = null;
//					if(builtinfunc.containsKey(key)) {
//						params = builtinfunc.get(key);
//					}else {
//						params = new ArrayList<RuleDataparams>();
//						builtinfunc.put(key, params);
//					}
//					params.add(rdp);
//				}
//
//				createBomField(resultMap,builtinfunc,builtinDataSets);
			//}
	        DataCache.setValue(cacheKey, resultMap);
//    	}
        return resultMap;
    }

    private void createBomField(Map<String, Bom> resultMap,Map<String,List<RuleDataparams>> dataparamsMap,List<RuleDataset> list){
		List<RuleDataparams> rList = null;
		Bom bom = null;
		BomField bf = null;
		List<BomField> bfList = null;
		for (RuleDataset rd : list) {
			bom = new Bom();
			bom.setId(rd.getId());
			bom.setName(rd.getName());
			bom.setLabel(rd.getChzn());
			bom.setParamType(rd.getParamType());
			bom.setDesc(rd.getDataDesc());
			bom.setDataType(rd.getName());
			bom.setType(BaseBean.TYPE_BOM);
			rList = dataparamsMap.get(rd.getId());
			bfList = new ArrayList<BomField>();
			bom.setBomFields(bfList);
			if( rList !=null && rList.size()>0 ) {
				for (RuleDataparams rdp : rList) {
					bf = new BomField();
					bf.setId(rdp.getId());
					bf.setDataType(rdp.getType());
					bf.setDesc(rdp.getParamDesc()); //mF.attributeValue("desc")

					bf.setName(rdp.getName());
					bf.setLabel(rdp.getChzn());//mF.attributeValue("chzn")
					bf.setType(BaseBean.OBJ_TYPE_FIELD);
					bf.setCollection(rdp.getCollection());
					bf.setPattern(rdp.getPattern());
					bf.setDomain(rdp.getDomain());
					bf.setDefaultValue(rdp.getDefaultValue());
					bf.setIsDerives(rdp.getIsDerives());
					bf.setIsfuncparam(rdp.getIsfuncparam());
					if(StringUtils.isEmpty(bf.getDataType())) {
						// 数据模型类型为空过滤掉
						continue;
					}
					if (isBaseType(bf.getDataType()) && (bf.getCollection() == null || !bf.getCollection().trim().equalsIgnoreCase("list"))) {
						bf.setGroupType("base");
					} else if (bf.getCollection() != null && bf.getCollection().trim().equalsIgnoreCase("list")) {
						bf.setGroupType("list");
					} else {
						bf.setGroupType("object");
					}
					bfList.add(bf);
				}
			}
			if(bom.getBomFields().size() > 0) {
				resultMap.put(rd.getName(), bom);
			}
		}
	}

    @SuppressWarnings("unchecked")
	public List<DataSetTreeVo> findBomListByProjCode(String projectCode) {
    	List<DataSetTreeVo> resultList = new ArrayList<DataSetTreeVo>();
    	String cacheKey = DataCache.getCacheKey(projectCode, DataCache.DATASETTREEVO_OPTION);
    	if(DataCache.canGetFromCache(cacheKey)) {
    		resultList = (List<DataSetTreeVo>) DataCache.getValue(cacheKey);
    	}else {
	        RuleDataparams ruleDataparams = null;
	        RuleDataset condition = new RuleDataset();
	        condition.setProjectcode(projectCode);
	        List<RuleDataset> list = this.ruleDatasetDao.findList(condition);
	        //查函数变量
	        RuleDataparams rdps = new RuleDataparams();
	        rdps.setProjectcode(projectCode);
	        List<RuleDataparams> rFuncList =  this.ruleDataparamsDao.findListForBom(rdps);
	        Map<String,List<RuleDataparams>> mapfunc = new HashMap<String,List<RuleDataparams>>();
	        for(RuleDataparams rdp:rFuncList) {
	        	String key = rdp.getDatasetId();
	        	 List<RuleDataparams> params = null;
	        	if(mapfunc.containsKey(key)) {
	        		params = mapfunc.get(key);
	        	}else {
	        		params = new ArrayList<RuleDataparams>();
	        		mapfunc.put(key, params);
	        	}
	        	params.add(rdp);
	        }
	        
	        //查全部变量
	        Map<String,List<RuleDataparams>> mapAll = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
	        
	        for (RuleDataset rd : list) {
	            DataSetTreeVo dataset = new DataSetTreeVo();
	            dataset.setId(rd.getId());
	            dataset.setName(rd.getChzn());
	            dataset.setNameEN(rd.getName());
	            dataset.setNoR(true);
	            dataset.setOpen(true);
	            dataset.setDataset(rd);
	            dataset.setRankRelationId(rd.getRankRelationId());
	            ruleDataparams = new RuleDataparams();
	            ruleDataparams.setProjectcode(rd.getProjectcode());
	            ruleDataparams.setDatasetId(rd.getId());
	            List<DataSetTreeVo> children = new ArrayList<DataSetTreeVo>();
				List<RuleDataparams> paramList = new ArrayList<>();
				if("funcparam".equals(rd.getParamType())){
					paramList = mapfunc.get(rd.getId());
				}else{
					paramList = mapAll.get(rd.getId());
				}
	            if (paramList == null || paramList.size() < 1) {
	            	dataset.setChildren(children);
	            	resultList.add(dataset);
	                continue;
	            }
	            for (RuleDataparams param : paramList) {
	                DataSetTreeVo paramdst = new DataSetTreeVo();
	                paramdst.setId(param.getId());
	                paramdst.setName(param.getChzn());
	                paramdst.setNameEN(param.getName());
	                paramdst.setNoR(true);
	                paramdst.setOpen(true);
	                paramdst.setParam(param);
	                children.add(paramdst);
	            }
	            dataset.setChildren(children);
	            resultList.add(dataset);
	        }
	        DataCache.setValue(cacheKey, resultList);
    	}
    	
        return resultList;
    }

    private static boolean isBaseType(String type) {
        return "String_Long_Double_Date_Boolean_".toLowerCase().indexOf(type.toLowerCase() + "_") >= 0;
    }

    @SuppressWarnings("unchecked")
	@Override
    public Map<String, RuleDataset> findRuleDataset(String projectCode) {
    	Map<String, RuleDataset> result = new HashMap<String, RuleDataset>();
    	String cacheKey = DataCache.getCacheKey(projectCode, DataCache.MAPRULEDATASET_OPTION);
    	if(DataCache.canGetFromCache(cacheKey)) {
    		result = (Map<String, RuleDataset>) DataCache.getValue(cacheKey);
    	}else {
	        RuleDataset ruleDataset = new RuleDataset();
	        ruleDataset.setProjectcode(projectCode);
	        List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
	        Map<String,List<RuleDataparams>> mapAll = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
	        Map<String, RuleDataparams> map = null;
	        for (RuleDataset dataset : list) {
	            result.put(dataset.getName(), dataset);
	            List<RuleDataparams> pList = mapAll.get(dataset.getId());
	            map = new HashMap<>();
	            dataset.setFieldMap(map);
	            dataset.setmFieldNames(new ArrayList<String>());
	            if( pList != null && pList.size() > 0 ) {
		            for (RuleDataparams pDataparams : pList) {
		                dataset.getmFieldNames().add(pDataparams.getName());
		                map.put(pDataparams.getName(), pDataparams);
		            }
	            }
	        }
	        DataCache.setValue(cacheKey, result);
    	}
        return result;
    }

    @SuppressWarnings("unchecked")
	@Override
    public Map<String, MClass> findMapClass(String projectCode) {
    	Map<String, MClass> result = new HashMap<String, MClass>();
    	String cacheKey = DataCache.getCacheKey(projectCode, DataCache.MCLASSCACHE_OPTION);
    	if(DataCache.canGetFromCache(cacheKey)) {
    		result = (Map<String, MClass>) DataCache.getValue(cacheKey);
    	}else {
	        RuleDataset ruleDataset = new RuleDataset();
	        ruleDataset.setProjectcode(projectCode);
	        List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
	        Map<String,List<RuleDataparams>> mapAll = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
	        Map<String, MField> map = null;
	        MClass mClass = null;
	        MField mField = null;
	        for (RuleDataset dataset : list) {
	            mClass = new MClass();
	            mClass.setChzn(dataset.getChzn());
	            mClass.setDesc(dataset.getDataDesc());
	            mClass.setName(dataset.getName());
	            mClass.setParamType(dataset.getParamType());
	            result.put(dataset.getName(), mClass);
	            List<RuleDataparams> pList = mapAll.get(dataset.getId());
	            map = new HashMap<String, MField>();
	            mClass.setFieldMap(map);
	            mClass.setmFieldNames(new ArrayList<String>());
	            if( pList != null && pList.size() > 0 ) {
		            for (RuleDataparams pDataparams : pList) {
		                mClass.getmFieldNames().add(pDataparams.getName());
		                mField = new MField();
		                mField.setChzn(pDataparams.getChzn());
		                mField.setCollection(pDataparams.getCollection());
		                mField.setDefaultValue(pDataparams.getDefaultValue());
		                mField.setDesc(pDataparams.getParamDesc());
		                mField.setDomain(pDataparams.getDomain());
		                mField.setDomainStr(pDataparams.getDomainStr());
		                mField.setId(pDataparams.getId());
		                mField.setIsCollections(pDataparams.getIsCollections());
		                mField.setIsDerives(pDataparams.getIsDerives());
		                mField.setIsout(pDataparams.getIsout());
		                mField.setMathStr(pDataparams.getMathStr());
		                mField.setName(pDataparams.getName());
		                mField.setPattern(pDataparams.getPattern());
		                mField.setType(pDataparams.getType());
		                map.put(pDataparams.getName(), mField);
		            }
	            }
	        }
	        DataCache.setValue(cacheKey,result);
    	}
        return result;
    }

    /**
     * 此方法仅用于全部数据模型导出
     */
    @Override
    public Map<String, MClass> findMapClass(String projectCode,String  buildin,String rankRelationId) {
        RuleDataset ruleDataset = new RuleDataset();
        ruleDataset.setProjectcode(projectCode);
        ruleDataset.setIsbuiltin(buildin);
        ruleDataset.setRankRelationId(rankRelationId);
        List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
        Map<String,List<RuleDataparams>> mapAll = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
        Map<String, MClass> result = new HashMap<>();
        Map<String, MField> map = null;
        MClass mClass = null;
        MField mField = null;
        for (RuleDataset dataset : list) {
        	if( !"funcparam".equals(dataset.getParamType()) ){
	            mClass = new MClass();
	            mClass.setChzn(dataset.getChzn());
	            mClass.setDesc(dataset.getDataDesc());
	            mClass.setName(dataset.getName());
	            mClass.setParamType(dataset.getParamType());
	            result.put(dataset.getName(), mClass);
	            List<RuleDataparams> pList = mapAll.get(dataset.getId());
	            map = new HashMap<>();
	            mClass.setFieldMap(map);
	            mClass.setmFieldNames(new ArrayList<String>());
	            if( pList != null && pList.size() > 0 ) {
		            for (RuleDataparams pDataparams : pList) {
		                mClass.getmFieldNames().add(pDataparams.getName());
		                mField = new MField();
		                mField.setChzn(pDataparams.getChzn());
		                mField.setCollection(pDataparams.getCollection());
		                mField.setDefaultValue(pDataparams.getDefaultValue());
		                mField.setDesc(pDataparams.getParamDesc());
		                mField.setDomain(pDataparams.getDomain());
		                mField.setDomainStr(pDataparams.getDomainStr());
		                mField.setId(pDataparams.getId());
		                mField.setIsCollections(pDataparams.getIsCollections());
		                mField.setIsDerives(pDataparams.getIsDerives());
		                mField.setIsout(pDataparams.getIsout());
		                mField.setMathStr(pDataparams.getMathStr());
		                mField.setName(pDataparams.getName());
		                mField.setPattern(pDataparams.getPattern());
		                mField.setType(pDataparams.getType());
		                map.put(pDataparams.getName(), mField);
		            }
	            }
        	}
        }
        return result;
    }
    
    /**
     * 此方法仅用于根据数据模型id的数据模型导出
     */
    @Override
    public Map<String, MClass> findMapClassByDataModelId(String projectCode,String  buildin, String datamodelid, String rankRelationId) {
        RuleDataset ruleDataset = new RuleDataset();
        ruleDataset.setProjectcode(projectCode);
        ruleDataset.setIsbuiltin(buildin);
        ruleDataset.setRankRelationId(rankRelationId);
        ruleDataset.setDatamodelid(datamodelid);
        List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
        Map<String,List<RuleDataparams>> mapAll = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
        Map<String, MClass> result = new HashMap<>();
        Map<String, MField> map = null;
        MClass mClass = null;
        MField mField = null;
        for (RuleDataset dataset : list) {
        	if( !"funcparam".equals(dataset.getParamType()) ){
	            mClass = new MClass();
	            mClass.setChzn(dataset.getChzn());
	            mClass.setDesc(dataset.getDataDesc());
	            mClass.setName(dataset.getName());
	            mClass.setParamType(dataset.getParamType());
	            result.put(dataset.getName(), mClass);
	            List<RuleDataparams> pList = mapAll.get(dataset.getId());
	            map = new HashMap<>();
	            mClass.setFieldMap(map);
	            mClass.setmFieldNames(new ArrayList<String>());
	            if( pList != null && pList.size() > 0 ) {
		            for (RuleDataparams pDataparams : pList) {
		                mClass.getmFieldNames().add(pDataparams.getName());
		                mField = new MField();
		                mField.setChzn(pDataparams.getChzn());
		                mField.setCollection(pDataparams.getCollection());
		                mField.setDefaultValue(pDataparams.getDefaultValue());
		                mField.setDesc(pDataparams.getParamDesc());
		                mField.setDomain(pDataparams.getDomain());
		                mField.setDomainStr(pDataparams.getDomainStr());
		                mField.setId(pDataparams.getId());
		                mField.setIsCollections(pDataparams.getIsCollections());
		                mField.setIsDerives(pDataparams.getIsDerives());
		                mField.setIsout(pDataparams.getIsout());
		                mField.setMathStr(pDataparams.getMathStr());
		                mField.setName(pDataparams.getName());
		                mField.setPattern(pDataparams.getPattern());
		                mField.setType(pDataparams.getType());
		                map.put(pDataparams.getName(), mField);
		            }
	            }
        	}
        }
        return result;
    }

    @Override
    public List<RuleDataDomain> findDataDomains(String domain, String projectCode) {
        RuleDataDomain domainInfo = new RuleDataDomain();
        domainInfo.setDomainId(domain);
        return this.ruleDataDomainDao.findList(domainInfo);

    }
    
    @Override
    public  List<RuleDataDomain> findDataDomains(String domain) {
    	Map<String, List<RuleDataDomain>> map = this.findDomainMap();
    	return  map.get(domain);
    }

    @Override
    public Map<String, BomField> findBomField(String projectCode) {
        RuleDataset ruleDataset = new RuleDataset();
        ruleDataset.setProjectcode(projectCode);
        List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
        Map<String,List<RuleDataparams>> mapAll = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
        BomField bf = null;

        Map<String, BomField> resultMap = new HashMap<>();
        for (RuleDataset rd : list) {
            List<RuleDataparams> rList = mapAll.get(rd.getId());
            if( rList != null && rList.size() > 0 ) {
	            for (RuleDataparams rdp : rList) {
	                bf = new BomField();
	                bf.setId(rdp.getId());
	                bf.setDataType(rdp.getType());
	                bf.setDesc(rdp.getParamDesc()); //mF.attributeValue("desc")
	                bf.setClassName(rd.getName());
	                bf.setName(rdp.getName());
	                bf.setLabel(rdp.getChzn());//mF.attributeValue("chzn")
	                bf.setType(BaseBean.TYPE_BOM);
	                bf.setCollection(rdp.getCollection());
	                bf.setPattern(rdp.getPattern());
	                bf.setDomain(rdp.getDomain());
	                bf.setDefaultValue(rdp.getDefaultValue());
	                bf.setIsDerives(rdp.getIsDerives());
	                resultMap.put(rd.getName() + "." + bf.getName(), bf);
	            }
            }
        }
        return resultMap;

    }
    
    @Override
	public List<RuleEnum> findRuleEnumByProjectCode(String projectCode) {
		RuleEnum ruleenum = new RuleEnum();
		ruleenum.setProjectCode(projectCode);
        List<RuleEnum> list = this.ruleEnumService.findList(ruleenum);
       
        RuleEnum r = new RuleEnum();
		r.setSearchEnumType(true);	
        List<RuleEnum> list2 = new ArrayList<RuleEnum>();
        list2 = ruleEnumService.findList(r);

        for (RuleEnum rdp : list) {
        	ruleenum = new RuleEnum();
        	ruleenum.setId(rdp.getId());
        	ruleenum.setEnumName(rdp.getEnumName());
        	ruleenum.setEnumCode(rdp.getEnumCode());
            for(RuleEnum e:list2){
            	if (e.getEnumCode().equals(rdp.getEnumType())) {
            		rdp.setEnumType(e.getEnumName());
				}
    		}
        }

        return list;
	}

	@Override
	public List<RuleEnum>  findRuleEnumTypeByProjectCode(String projectCode) {
		RuleEnum ruleenum = new RuleEnum();
		ruleenum.setProjectCode(projectCode);
        RuleEnum r = new RuleEnum();
		r.setSearchEnumType(true);	
        List<RuleEnum> list = new ArrayList<RuleEnum>();
        list = ruleEnumService.findList(r);
        return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, List<RuleDataDomain>> findDomainMap() {
		Map<String,List<RuleDataDomain>> resultMap = new HashMap<String,List<RuleDataDomain>>();
    	String cacheKey = DataCache.getCacheKey("", DataCache.DOMAINMAP_OPTION);
    	if(DataCache.canGetFromCache(cacheKey)) {
    		resultMap = (Map<String, List<RuleDataDomain>>) DataCache.getValue(cacheKey);
    	}else {
	        RuleDataDomain domainInfo = new RuleDataDomain();
	        List<RuleDataDomain> domains = this.ruleDataDomainDao.findList(domainInfo);
	        List<RuleDataDomain> domainList = null;
	        for(RuleDataDomain domain:domains) {
	        	String key = domain.getDomainId();
	        	if(resultMap.containsKey(key)) {
	        		domainList = resultMap.get(key);
	        	}else {
	        		domainList = new ArrayList<RuleDataDomain>();
	        		resultMap.put(key, domainList);
	        	}
	        	domainList.add(domain);
	        }
	        DataCache.setValue(cacheKey, resultMap);
    	}
	    return resultMap;
	}
    @Override
    public  List<DataParamTreeVO>  findDataParam(String projectCode,String rankRelationId) throws Exception{
    	 List<DataSetTreeVo> list =  this.findBomListByProjCodeRecursion(projectCode, rankRelationId);
    	 List<DataParamTreeVO> resList  = new ArrayList<>();
    	 DataParamTreeVO  dataParamVO  = null;
    	 for(DataSetTreeVo dsTree: list) {
    		 dataParamVO = new DataParamTreeVO();
    		 dataParamVO.setChecked(false);
    		 dataParamVO.setId(dsTree.getId());
    		 dataParamVO.setPId("0");
    		 dataParamVO.setName(dsTree.getName());
    		 dataParamVO.setNameEN(dsTree.getNameEN());
    		 dataParamVO.setClassName(dsTree.getDataset().getName());
    		 resList.add(dataParamVO);
    		 for (DataSetTreeVo paramTree: dsTree.getChildren()) {
    			 dataParamVO  = new  DataParamTreeVO();
    			 dataParamVO.setChecked(true);
    			 dataParamVO.setId(paramTree.getId());
    			 dataParamVO.setPId(dsTree.getId());
    			 dataParamVO.setName(paramTree.getName());
    			 dataParamVO.setNameEN(paramTree.getNameEN());
    			 dataParamVO.setLabel(dsTree.getName());
    			 dataParamVO.setClassName(dsTree.getDataset().getName());
    			 RuleParamField  param = new RuleParamField();
    			 param.setClassName(dataParamVO.getClassName());
    			 BeanUtils.copyProperties(param, paramTree.getParam());
    			 dataParamVO.setParam(param);
    			 resList.add(dataParamVO);
    		 }
    	 }
    	 return resList;
    }
    
    @Override
    public  List<DataParamTreeVO>  findDataParam(String projectCode,String rankRelationId,String  selectSets) throws Exception{
	   	 List<DataSetTreeVo> list =  this.findBomListByProjCodeRecursion(projectCode, rankRelationId);
	   	 String[]  sets = null;   			 
	   	 List<String> sList = null;
	   	 if (!StringUtils.isEmpty(selectSets)) {
	   		sets =StringUtils.split(selectSets, ",");
	   	    List<String> jList =CollectionUtils.arrayToList(sets);
	   	    sList = new ArrayList<>(jList);
	   	    sList.add("func");
	   	    sList.add("builtinParam");
	   	 }   			
	   	 List<DataParamTreeVO> resList  = new ArrayList<>();
	   	 DataParamTreeVO  dataParamVO  = null;
	   	final BeanCopier beanCopier=  BeanCopier.create(RuleDataparams.class, RuleParamField.class, false);
	   	 for(DataSetTreeVo dsTree: list) {
	   		 if (sList != null && !sList.contains(dsTree.getNameEN())) {
	   			 continue;
	   		 }
	   		 dataParamVO = new DataParamTreeVO();
	   		 dataParamVO.setChecked(false);
	   		 dataParamVO.setId(dsTree.getId());
	   		 dataParamVO.setPId("0");
	   		 dataParamVO.setName(dsTree.getName());
	   		 dataParamVO.setNameEN(dsTree.getNameEN());
	   		 dataParamVO.setClassName(dsTree.getDataset().getName());
	   		 resList.add(dataParamVO);
	   		 for (DataSetTreeVo paramTree: dsTree.getChildren()) {
	   			 dataParamVO  = new  DataParamTreeVO();
	   			 dataParamVO.setChecked(true);
	   			 dataParamVO.setId(paramTree.getId());
	   			 dataParamVO.setPId(dsTree.getId());
	   			 dataParamVO.setName(paramTree.getName());
	   			 dataParamVO.setNameEN(paramTree.getNameEN());
	   			 dataParamVO.setLabel(dsTree.getName());
	   			 dataParamVO.setClassName(dsTree.getDataset().getName());
	   			 RuleParamField  param = new RuleParamField();
	   			 param.setClassName(dataParamVO.getClassName());
//	   			 BeanUtils.copyProperties(param, paramTree.getParam());
	   			beanCopier.copy(paramTree.getParam(), param, null);
	   			 dataParamVO.setParam(param);
	   			 resList.add(dataParamVO);
	   		 }
	   	 }
	   	 return resList;
    }
    
    @Override
    public  List<DataParamTreeVO>  findDatasetList(ProjectInfo  projectInfo) throws Exception{
		   	 List<DataSetTreeVo> list =  this.findBomListByProjCodeRecursion(projectInfo.getProjectCode(), projectInfo.getRankRelationId());
		   	 List<DataParamTreeVO> resList  = new ArrayList<>();
		   	 DataParamTreeVO  dataParamVO  = null;
		   	 String  selected = projectInfo.getSelected();
		     List<String>  seleList =null;
		     if (!StringUtils.isEmpty(selected)) {
		    	 seleList =   CollectionUtils.arrayToList(selected);		    	 
		     }		   
	    	 for(DataSetTreeVo dsTree: list) {
	    		 dataParamVO = new DataParamTreeVO();
	    		 if (selected != null && seleList.contains(dsTree.getNameEN())) {
	    			 dataParamVO.setChecked(true); 
	    		 }else 
	    		    dataParamVO.setChecked(false);
	    		 dataParamVO.setId(dsTree.getNameEN());
	    		 dataParamVO.setPId("0");
	    		 dataParamVO.setName(dsTree.getName());
	    		 dataParamVO.setNameEN(dsTree.getNameEN());
	    		 dataParamVO.setClassName(dsTree.getDataset().getName());
	    		 resList.add(dataParamVO);
	    	 }	
	    	 return  resList;
    }

    /**
     * 获取变量列表（包括引用项目变量）--除了规则集之外的所有组件使用
     */
    public List<DataSetTreeVo> findBomListByProjCode(String projectCode,String rankRelationId) {
        rankRelationId = (rankRelationId==null?"":rankRelationId);

        List<DataSetTreeVo> projectList = new ArrayList<DataSetTreeVo>();
        if(PARAMAP.containsKey(projectCode+rankRelationId)) {
            projectList = PARAMAP.get(projectCode+rankRelationId);
            return projectList;
        }
        projectList = createBomList(projectCode, rankRelationId);
        //获取当前项目所依赖的项目code集合
        List<String> refProCodeList = ruleReferenceDao.getRefProCode(projectCode);
        if(refProCodeList!=null&&refProCodeList.size()>0){
            for(String refCode :refProCodeList){
                List<DataSetTreeVo> tmpList = createBomList(refCode,null);
                projectList.addAll(tmpList);
            }
        }
        PARAMAP.put(projectCode+rankRelationId, projectList);
        return projectList;
    }
    
    public List<DataSetTreeVo> findBomListByProjCodeRecursion(String projectCode,String rankRelationId) {
    	List<DataSetTreeVo> resultList = this.findBomListByProjCode(projectCode);
    	List<String> ids = ruleProjectRankService.findIdsByRecursion(rankRelationId, "dataModel");
    	Map<String,Object> map = new HashMap<String,Object>();
    	map.put("projectCode", projectCode);
    	map.put("rankList", ids);
    	List<RuleDatamodel> dataModelList = ruleDatamodelDao.findRuleDatamodelListByProRank(map);
    	List<String> dataModelIds = dataModelList.stream().map(RuleDatamodel::getId).collect(Collectors.toList());
    	List<DataSetTreeVo> projectList = new ArrayList<DataSetTreeVo>();
    	for(DataSetTreeVo vo:resultList) {
    		if(!dataModelIds.contains(vo.getDataset().getDatamodelid())&&!"func".equals(vo.getNameEN())){//内置变量和规则集产生的数据集没有datamodelid  过滤
    			continue;
			}
    		if( (ids.size() == 0 || ids.contains(vo.getRankRelationId()) || StringUtils.isEmpty(vo.getRankRelationId())) && !vo.getChildren().isEmpty()) {
    			projectList.add(vo);
    			continue;
    		}
    		if(dataModelIds==null || dataModelIds.isEmpty()) {
    			projectList.add(vo);
    		}else if(dataModelIds.contains(vo.getDataset().getDatamodelid()) && !vo.getChildren().isEmpty()) {
    			projectList.add(vo);
    		}
    	}
        return projectList;
    }
    public  List<DataSetTreeVo> createBomList(String projectCode,String rankRelationId){
        List<DataSetTreeVo> projectList = new ArrayList<DataSetTreeVo>();
        List<DataSetTreeVo> resultList = new ArrayList<DataSetTreeVo>();
        RuleProject ruleProject = ruleProjectDao.getByCodeForRef(projectCode);
        DataSetTreeVo projectDataSet = new DataSetTreeVo();
        projectDataSet.setId(ruleProject.getId());
        projectDataSet.setName(ruleProject.getProjectname());
        projectDataSet.setNameEN(ruleProject.getProjectcode());
        projectDataSet.setNoR(true);
        projectDataSet.setOpen(true);
        projectDataSet.setDataset(null);
        RuleDataset rds = new RuleDataset();
        projectDataSet.setDataset(rds);
        Map<String,  List<RuleDataparams>> paramListMap = findParamList(projectCode);
        List<String> rankIdStrList = getRankRelationInfo(projectCode,rankRelationId,"dataModel");
        Map<String,Object> existMap = new HashMap<>();
        if(rankIdStrList!=null && rankIdStrList.size()>0) {
            for (String rankId : rankIdStrList) {
                getBomList(projectCode,rankId,paramListMap,resultList,existMap);
            }
        }else {
            getBomList(projectCode,null,paramListMap,resultList,existMap);
        }
        projectDataSet.setChildren(resultList);
        projectList.add(projectDataSet);
        return projectList;
    }
    private void getBomList(String projectCode,String rankId,Map<String,List<RuleDataparams>> paramListMap,List<DataSetTreeVo> resultList,Map<String,Object> existMap) {
        RuleDataset condition = new RuleDataset();
        if(!StringUtils.isEmpty(rankId)) {
        	condition.setRankRelationId(rankId);
        }
        condition.setProjectcode(projectCode);
        List<RuleDataset> list = this.ruleDatasetDao.findList(condition);
        for (RuleDataset rd : list) {
            DataSetTreeVo dataset = new DataSetTreeVo();
            dataset.setId(rd.getId());
            dataset.setName(rd.getChzn());
            dataset.setNameEN(rd.getName());
            dataset.setNoR(true);
            dataset.setOpen(true);
            dataset.setDataset(rd);
            if (paramListMap.get(rd.getId()) == null) {
                continue;
            }
            if(existMap.containsKey(rd.getId()))
            	continue;
            existMap.put(rd.getId(), rd);
            List<DataSetTreeVo> children = new ArrayList<DataSetTreeVo>();
            List<RuleDataparams> paramList = paramListMap.get(rd.getId());
            for (RuleDataparams param : paramList) {
                DataSetTreeVo paramdst = new DataSetTreeVo();
                paramdst.setId(rd.getName() + param.getName());
                paramdst.setName(param.getChzn());
                paramdst.setNameEN(param.getName());
                paramdst.setNoR(true);
                paramdst.setOpen(true);
                paramdst.setParam(param);
                children.add(paramdst);
            }
            dataset.setParam(new RuleDataparams());//新增
            dataset.setChildren(children);
            resultList.add(dataset);
        }
    }


    public Map<String, Bom> createBomMapVo(String projectCode,String rankRelationId){
    	rankRelationId = (rankRelationId==null?"":rankRelationId);
    	if(BOMMAP.containsKey(projectCode+rankRelationId)) {
    		return BOMMAP.get(projectCode+rankRelationId);
    	}
    	Map<String, Bom> resultMap = new HashMap<>();
    	Map<String,  List<RuleDataparams>> paramListMap = findParamList(projectCode);
    	List<String> rankIdStrList = getRankRelationInfo(projectCode,rankRelationId,"dataModel");
    	if(rankIdStrList!=null && rankIdStrList.size()>0) {
        	for (String rankId : rankIdStrList) {
        		getBomMap(projectCode,rankId,paramListMap,resultMap);
    		}
    	}else {
    		getBomMap(projectCode,null,paramListMap,resultMap);
    	}
    	BOMMAP.put(projectCode+rankRelationId, resultMap);
    	return resultMap;
    }
    
    private Map<String,  List<RuleDataparams>> findParamList (String projectCode) {
        Map<String , List<RuleDataparams>> rMap = new HashMap<>();
        RuleDataparams ruleDataparams = new RuleDataparams();
        ruleDataparams.setProjectcode(projectCode);
       // ruleDataparams.setSysParamFlag("1");
        List<RuleDataparams> paramList = this.ruleDataparamsDao.findList(ruleDataparams);
        if(paramList == null || paramList.size() < 1){
            return rMap;
        }
        for(RuleDataparams param : paramList){
            if(rMap.get(param.getDatasetId()) == null){
                List<RuleDataparams> list = new ArrayList<>();
                list.add(param);
                rMap.put(param.getDatasetId(),list);
            }else{
                rMap.get(param.getDatasetId()).add(param);
            }
        }
        return rMap;
    }

    /**
     * 获取层级文件及父级目录数据模型层级关系信息
     * @param projectCode
     * @param rankRelationId
     * @return
     */
    private List<String> getRankRelationInfo(String projectCode,String rankRelationId,String moduleType) {
    	List<String> rankIdStrList = new ArrayList<>();
    	RuleProjectRank baseRank = ruleProjectRankService.get(rankRelationId);
    	if(baseRank!=null){
    		List<RuleProjectRank> baseRankList = new ArrayList<>();
        	baseRankList.add(baseRank);
        	recursionRankInfo(baseRankList,rankIdStrList,moduleType);
    	}
    	return rankIdStrList;
    }
    //找到与当前模块对应相同父级的数据模型
    //添加到返回集合
    //找到与当前模块父节点相同父级的数据模型
    //添加到返回集合
    private List<String> recursionRankInfo(List<RuleProjectRank> baseRankList,List<String> rankIdStrList,String moduleType) {
    	for (RuleProjectRank ruleProjectRank : baseRankList) {
    		RuleProjectRank condition = new RuleProjectRank();
	    	condition.setProjectCode(ruleProjectRank.getProjectCode());
	    	//condition.setModuleType("dataModel");
			condition.setModuleType(moduleType);
    		condition.setPId(ruleProjectRank.getPId());
    		List<RuleProjectRank> rankList = ruleProjectRankService.findList(condition);
    		for (RuleProjectRank ruleProjectRank2 : rankList) {
    			rankIdStrList.add(ruleProjectRank2.getTid());
			}
    		condition = new RuleProjectRank();
	    	condition.setProjectCode(ruleProjectRank.getProjectCode());
    		condition.setNodeId(ruleProjectRank.getPId());
    		List<RuleProjectRank> tmpFileList = ruleProjectRankService.findList(condition);
    		if(tmpFileList!=null)
    			rankIdStrList = recursionRankInfo(tmpFileList,rankIdStrList,moduleType);
		}
    	return rankIdStrList;
    }
    
    private void getBomMap(String projectCode,String rankId,Map<String,List<RuleDataparams>> paramListMap,Map<String, Bom> resultMap) {
        RuleDataset ruleDataset = new RuleDataset();
        if(!StringUtils.isEmpty(rankId)) {
       	 ruleDataset.setRankRelationId(rankId);
        }
        ruleDataset.setProjectcode(projectCode);
        List<RuleDataset> list = this.ruleDatasetDao.findList(ruleDataset);
        Bom bom = null;
        RuleDataparams ruleDataparams = null;
        BomField bf = null;
        List<BomField> bfList = null;
        Map<String,BomField> bomFieldMap = null;
        for (RuleDataset rd : list) {
            bom = new Bom();
            bom.setId(rd.getId());
            bom.setName(rd.getName());
            bom.setLabel(rd.getChzn());
            bom.setParamType(rd.getParamType());
            bom.setDesc(rd.getDataDesc());
            bom.setDataType(rd.getName());
            bom.setType(BaseBean.TYPE_BOM);
            resultMap.put(rd.getName(), bom);
            ruleDataparams = new RuleDataparams();
            ruleDataparams.setDatasetId(rd.getId());
            List<RuleDataparams> rList = paramListMap.get(rd.getId());
            if(rList==null) {
           	System.out.println("not fount param,datasetId:"+rd.getId());
           	 continue;
            }
            bfList = new ArrayList<BomField>();
            bomFieldMap = new HashMap<String,BomField>();
            bom.setBomFields(bfList);
            bom.setBomFieldMap(bomFieldMap);
            for (RuleDataparams rdp : rList) {
                bf = new BomField();
                bf.setId(rdp.getId());
                bf.setDataType(rdp.getType());
                bf.setDesc(rdp.getParamDesc()); //mF.attributeValue("desc")
                //bf.setReferenceProjectCode(rdp.getProjectcode());
                bf.setName(rdp.getName());
                bf.setLabel(rdp.getChzn());//mF.attributeValue("chzn")
                bf.setType(BaseBean.TYPE_BOM);
                bf.setCollection(rdp.getCollection());
                bf.setPattern(rdp.getPattern());
                bf.setDomain(rdp.getDomain());
                bf.setDefaultValue(rdp.getDefaultValue());
                bf.setIsDerives(rdp.getIsDerives());
                if (isBaseType(bf.getDataType()) && (bf.getCollection() == null || !bf.getCollection().trim().equalsIgnoreCase("list"))) {
                    bf.setGroupType("base");
                } else if (bf.getCollection() != null && bf.getCollection().trim().equalsIgnoreCase("list")) {
                    bf.setGroupType("list");
                } else {
                    bf.setGroupType("object");
                }
                bomFieldMap.put(bf.getName(), bf);
                bfList.add(bf);
            }
        }
   }

    //层级隔离中缓存元数据的Key
	private RuleProjectRank getCacheKeyWithRanRelation(String projectCode,String rankRelationId) throws BizException {
		//规则和决策树共用的方法，以当前层级的父节点的层级id作为缓存的Key start
	RuleProjectRank baseRank = ruleProjectRankService.get(rankRelationId);
	if(StringUtils.isEmpty(rankRelationId) || baseRank ==null){
		logger.error("项目编码为:"+projectCode+"在获取配置规则原数据时候，层级Id为空或者层级Id不存在，请确认！");
		throw new RuntimeException("项目编码为:"+projectCode+"在获取配置规则原数据时候，层级Id为空或者层级Id不存在，请确认！");
	}
	RuleProjectRank condition = new RuleProjectRank();
	condition.setProjectCode(projectCode);
	condition.setNodeId(baseRank.getPId());
	List<RuleProjectRank> parentRanks = ruleProjectRankService.findList(condition);
	if(parentRanks ==null || parentRanks.size()==0){
		logger.error("项目编码为:"+projectCode+",层级Id为:"+rankRelationId+"获取父级层级Id失败！");
		throw new RuntimeException("项目编码为:"+projectCode+",层级Id为:"+rankRelationId+"获取父级层级Id失败！");
	}
	//规则和决策树共用的方法，以当前层级的父节点的层级id作为缓存的Key end
      return parentRanks.get(0);
	}

}
